package com.itheima.service.ServiceImpl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.Service.UserLoginService;
import com.itheima.Service.UserOrderService;
import com.itheima.mapper.AdminOderMapper;
import com.itheima.mapper.UserOrderMapper;
import com.itheima.pojo.Order;
import com.itheima.pojo.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class UserOrderServiceImpl implements UserOrderService {
    @Autowired
    private UserOrderMapper userOrderMapper;
    @Autowired
    private UserLoginService userLoginService;
    @Autowired
    private AdminOderMapper adminOderMapper;
    @Override
    public void updateUserOrder(Order userOrder) {
        userOrder.setUpdateTime(LocalDateTime.now());
        userOrderMapper.updateUserOrder(userOrder);
    }

    @Override
    public Order getById(Integer id) {
        return userOrderMapper.getById(id);
    }

    @Override
    public PageBean page(Order query) {
        //设置分页参数
        PageHelper.startPage(query.getPage(), query.getPageSize());
        //执行查询
        Page<Order> list = userOrderMapper.page(query);

        return new PageBean(list.getTotal(), list.getResult());
    }

    @Override
    public void delete(Integer id) {
        userOrderMapper.deleteById(id);
    }

    @Override
    public void add(Order order) {
        userOrderMapper.add(order);
    }
}
